
package com.jsu.collegestudentadmissionsystem.controller;

import com.jsu.collegestudentadmissionsystem.pojo.dto.AdmissionBatchInfo;
import com.jsu.collegestudentadmissionsystem.service.StudentService;
import com.jsu.collegestudentadmissionsystem.utils.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.List;
import java.util.Scanner;


@Controller
public class StudentController {

    @Autowired
    StudentService studentService;

    Integer studentId;

    private void searchInfo(){ studentService.queryStudentInfo(this.studentId); }
//    private void searchCourseInfo () {
//        studentService.queryStudentCourseInfo(this.studentId);
//    }

    private void insertInfo(){
        System.out.println("请依次输入：姓名、性别、出生日期、户籍所在地");
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String [] mid = str.split(" ");
        studentService.insertStudentInfo(this.studentId,mid[0],mid[1],mid[2],mid[3]);
        searchInfo();
    }

    private void selectExamSubjects(){
        System.out.println("考试科目：1.物理，2.历史\n请从中任意选择一门：");
        Scanner sc = new Scanner(System.in);
        Integer x1 = sc.nextInt();
        System.out.println("考试科目：3.政治，4.生物，5.化学，6.地理\n请从中任意选择两门：");
        Integer x2 = sc.nextInt();
        Integer x3 = sc.nextInt();String [] str=new String [] {"物理","历史","政治","生物","化学","地理"};
        studentService.selectExamSubjects(this.studentId,str[x1-1],str[x2-1],str[x3-1]);
        searchInfo();
    }

    private void searchScoreRank(){
        studentService.searchSubjects(this.studentId);
        studentService.searchScoreRank(this.studentId);
    }

    private void searchCollegeBasicInfo(){
        while (true){
            System.out.println("请选择查询方式：\n1.按批次查询，2.按名称模糊查询，3.按代码模糊查询 4.返回上一步");
            Scanner sc = new Scanner(System.in);
            Integer operation = sc.nextInt();
            if(operation==4) {
                break;
            }
            switch (operation){
                case 1 :
                    searchCollegeInfoByBath(); break;
                case 2 :
                    searchCollegeInfoByName(); break;
                case 3 :
                    searchCollegeInfoByCode(); break;
            }
        }
    }

    private void searchCollegeMajorInfo(){
        System.out.println("请输入院校名称或院校代码");
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        studentService.searchCollegeMajorInfo(str);
    }

    private void searchCollegeInfoByBath(){
        System.out.println("请选择需要查询的批次：\n1.本科一批，2.本科二批，3.专科一批，4.专科二批");
        Scanner sc = new Scanner(System.in);
        Integer bath = sc.nextInt();
        studentService.searchCollegeInfoByBath(bath);
    }

    private void searchCollegeInfoByName(){
        System.out.println("请输入院校名称");
        Scanner sc = new Scanner(System.in);
        String str =sc.next();
        studentService.searchCollegeInfoByName(str);
    }

    private void searchCollegeInfoByCode(){
        System.out.println("请输入院校代码");
        Scanner sc = new Scanner(System.in);
        String str =sc.next();
        studentService.searchCollegeInfoByCode(str);
    }

    private void searchCollegeInfo(){
        while (true){
            System.out.println("请选择查询内容：\n1.查询院校基本信息，2.查询院校专业信息，3.退出查询");
            Scanner sc = new Scanner(System.in);
            Integer operation = sc.nextInt();
            if(operation==3) {
                break;
            }
            switch (operation){
                case 1 :
                    searchCollegeBasicInfo(); break;
                case 2 :
                    searchCollegeMajorInfo(); break;
            }
        }
    }

    private void searchStudentChoiceList(){ studentService.searchStudentChoiceList(this.studentId); }

    private void deleteStudentChoice(){
        System.out.println("请输入需要删除的志愿信息的院校优先级和专业优先级:");
        Scanner sc = new Scanner(System.in);
        Integer collegePriority = sc.nextInt();
        Integer majorPriority =sc.nextInt();
        studentService.deleteStudentChoice(this.studentId,collegePriority,majorPriority);
        studentService.searchStudentChoiceList(this.studentId);
    }

    private void updateStudentChoice(){
        System.out.println("请输入需要修改的志愿信息的院校优先级和专业优先级:");
        Scanner sc = new Scanner(System.in);
        Integer collegePriority = sc.nextInt();
        Integer majorPriority =sc.nextInt();
//        studentService.updateStudentChoice(this.studentId,collegePriority,majorPriority);
        System.out.println("请输入修改后的");
        studentService.searchStudentChoiceList(this.studentId);
    }

    private void fillStudentChoice(){
        System.out.println("请输入依次院校代码、专业代码、院校优先级、专业优先级");
        Scanner sc = new Scanner(System.in);
        String collegeCode = sc.next();
        String majorCode = sc.next();
        Integer collegePriority = sc.nextInt();
        Integer majorPriority =sc.nextInt();
        studentService.fillStudentChoice(this.studentId,collegeCode,majorCode,collegePriority,majorPriority);
        studentService.searchStudentChoiceList(this.studentId);
    }

    private void searchEnrollmentInfo(){ studentService.searchEnrollmentInfo(this.studentId); }

    public void setStudentId(Integer studentId){
        this.studentId=studentId;
    }

    private void searchStudentList(){
        studentService.searchStudentList();
    }

    public void dispatch(Integer operation ){
        switch (operation){
            case 0 :
                searchStudentList(); break;
            case 1 :
                searchInfo(); break;
            case 2 :
                insertInfo(); break;
            case 3 :
                selectExamSubjects(); break;
            case 4 :
                searchScoreRank(); break;
            case 5 :
                searchCollegeInfo(); break;
            case 6 :
                searchStudentChoiceList(); break;
            case 7 :
                fillStudentChoice(); break;
            case 8 :
                updateStudentChoice(); break;
            case 9 :
                deleteStudentChoice(); break;
            case 10 :
                searchEnrollmentInfo(); break;
        }
    }
}

